package com.hongxun.modules.csg.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.AddGroup;
import com.hongxun.common.validator.group.UpdateGroup;
import com.hongxun.modules.csg.entity.CMiddleCheckEntity;
import com.hongxun.modules.csg.service.CMiddleCheckService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.csg.entity.CLinePitEntity;
import com.hongxun.modules.csg.service.CLinePitService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 隐蔽工程：拉线坑
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-08-30 14:42:52
 */
@RestController
@RequestMapping("/csg/clinepit")
public class CLinePitController {
	@Autowired
	private CLinePitService cLinePitService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("mCGuid")!=null&&!query.get("mCGuid").toString().equals(""))
		{
			wheres+=" and  m_c_guid = '" + query.get("mCGuid").toString()+"' ";
		}
		if(query.get("state")!=null&&query.get("state").toString().equals("isdelno")) {
			wheres += " and  l_p_datastate != '删除' ";
		}
        query.put("filterSql",wheres+" ");

		List<CLinePitEntity> cLinePitList = cLinePitService.queryList(query);
		int total = cLinePitService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cLinePitList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}



	@RequestMapping("/select")
	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}

		wheres+=" and  l_p_datastate != '删除' ";
		query.put("filterSql",wheres+" ");
		List<CLinePitEntity> cLinePitEntityList = cLinePitService.queryList(query);
		return R.ok().put("returnlist", cLinePitEntityList);
	}




	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		CLinePitEntity cLinePit = cLinePitService.queryObject(guid);
		
		return R.ok().put("cLinePit", cLinePit);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody CLinePitEntity cLinePit){
		cLinePit.setLPDatastate("新增");
		cLinePitService.save(cLinePit);
		
		return R.ok();
	}

	/**
	 * 新增拉线坑
	 * @param
	 * @param guid
	 * @return
	 */
	@RequestMapping("/saveNew/{mCGuid}/{pGuid}")
	public R save(@RequestBody CLinePitEntity cLinePit,@PathVariable("mCGuid") String guid ,@PathVariable("pGuid") String pGuid){
		ValidatorUtils.validateEntity(cLinePit, AddGroup.class);
		cLinePit.setMCGuid(guid);
		cLinePit.setPGuid(pGuid);
		cLinePit.setMCName("拉线坑");
		cLinePit.setLPDatastate("新增");
		cLinePitService.save(cLinePit);
		return R.ok();
	}

	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody CLinePitEntity cLinePit){
		ValidatorUtils.validateEntity(cLinePit, UpdateGroup.class);
		cLinePit.setLPDatastate("修改");
		cLinePitService.update(cLinePit);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		cLinePitService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
